package com.ai.daofa; /*
 * @author: changchun.liang
 * @date: 2024/4/6
 * @Email: liangcc0309@dingtalk.com
 */

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

import cn.hutool.core.math.Combination;
import cn.hutool.core.util.ArrayUtil;

public class BrainFace {
    private LeftBrainFace leftBrain;
    private RightBrainFace rightBrain;

    public void putInWord(String word){

    }

    public String askOutWord(String word){
        return "";
    }

    /**
     * 练习学习文章
     * @param word
     */
    public void practiceInWord(String word) throws IOException {
        Yuan sy = new Yuan();
        sy.setToken(word);
        sy.savePractice(word);
        sy.initKeyWord();
        //排列组合内容
        String[] ws = new String[word.length()];
        for (int i=0;i<word.length();i++) {
            String c = word.substring(i,i+1);
            ws[i] = c;
        }
        Combination combination = new Combination(ws);
        //学习判断
        //1.关键字学习判断
        List<String[]> rs = combination.selectAll();
        rs.forEach(o->{
               String wordRdn = Arrays.toString(o).replaceAll("[\\[\\], ]", "");
                System.out.println(wordRdn +" 是关键字吗?");
                Scanner scanner = new Scanner(System.in);
                System.out.println("请输入文本框(按enter结束)");
                String input = scanner.nextLine();
                if ("Y".equals(input) || "是".equals(input)) {
                    try {
                        sy.saveKeyWord(wordRdn);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
           });
        //是否创建词类
        createCiLei(sy);
        //关键词与词类型绑定
        bindLeiXing(sy,rs);
        //绑定这句话的含义
        createMing(sy);
    }

    public void createCiLei(Yuan sy){
        System.out.println("是否继续创建新的词类型?");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文本框(按enter结束)");
        String ciLei = scanner.nextLine();
        try {
            if (ciLei.contains("创建") || ciLei.contains("create")) {
                String newCiLei = ciLei.replace("创建", "").replace("create", "").trim();
                sy.saveCiLei(newCiLei);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if ("1".equals(ciLei) || "N".equals(ciLei)|| "n".equals(ciLei) || "否".equals(ciLei)|| "不用".equals(ciLei)){
            } else {
                createCiLei(sy);
            }
        }
    }

    public void bindLeiXing(Yuan sy,List<String[]> rs){
        sy.bindLeiXing(rs);
    }

    public void createMing(Yuan sy){
        sy.bindMing();
    }
}
